package com.cn.http.http;

import java.io.*;
import java.net.URL;

public class DownloadM3U8AndT2 {

    public static void main(String[] args) {
        String m3u8Url = "https://t25.cdn2020.com/video/m3u8/2024/08/15/d799a5a9/index.m3u8"; // M3U8 文件 URL
        String downloadDir = "/Users/apple/Desktop/video/"; // 下载目录

        try {
            downloadFile(m3u8Url, downloadDir + "playlist.ts");

            System.out.println("下载完成！");
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("下载失败！");
        }
    }

    private static void downloadFile(String urlStr, String destFile) throws IOException {
        URL url = new URL(urlStr);
        try (InputStream in = url.openStream(); FileOutputStream fos = new FileOutputStream(destFile)) {
            byte[] buffer = new byte[1024];
            int bytesRead;
            while ((bytesRead = in.read(buffer)) != -1) {
                fos.write(buffer, 0, bytesRead);
            }
        }
    }


}
